﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using WmsApp.WmsService;

namespace WmsApp.Service
{
    public class GoodsCodeTypeService : IEntityService<GoodsCodeType, GoodsCodeTypeService>
    {

        #region IEntityService<Customer> Members

        public List<GoodsCodeType> GetEntityList()
        {
            var sc = Factory.WmsServiceFactory.GetServiceClient();
            List<GoodsCodeType> list = sc.GetGoodsCodeTypes();
            foreach (var goodsCodeType in list)
            {
                goodsCodeType.BindPropertyChanged();
            }
            return list;
        }

        public List<GoodsCodeType> GetEntityList(string condition)
        {
            var list = Factory.WmsServiceFactory.GetServiceClient().GetGoodsCodeTypesByCondition(condition);
            foreach (var goodsCodeType in list)
            {
                goodsCodeType.BindPropertyChanged();
            }
            return list;
        }


        public void SaveEntityList(List<GoodsCodeType> list)
        {
            var sc = Factory.WmsServiceFactory.GetServiceClient();
            foreach (var goodsCodeType in list)
            {
                if(string.IsNullOrEmpty(goodsCodeType.ExtVarChar3))
                {
                    goodsCodeType.ExtVarChar3 = "1";
                }
            }
            sc.SaveGoodsCodeTypes(list);
            foreach (var c in list)
            {
                c.WcfEntityState = EntityState.Unchanged;
            }
        }

        public GoodsCodeType GetEntity(string key)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
